#include<iostream>

using namespace std;
const int N = 100010;

int q[N], hh, tt = -1;

//向队尾插入
void push(int x){
    q[++ tt] = x;
}
//弹出
void pop(){
    hh ++;
}
//判断
bool empty(){
    if(hh <= tt) return false;
    return true;
}
//查询队头
int query(){
    return q[hh];
}

int main(){
    int m;
    cin >> m;
    while(m --){
        string op;
        cin >> op;
        if(op == "push"){
            int x;
            cin >> x;
            push(x);
        }
        else if(op == "empty"){
            if(!empty()) cout << "NO" << endl;
            else cout << "YES" << endl;
        }
        else if(op == "pop") pop();
        else cout << query() << endl;
    }
    return 0;
}